<?php

/**
 * 实名认证返回的错误码 对照表
 */
class Errcode
{
    private $code;

    public function __construct($code)
    {
        $this->code = $code;
    }

    /**
     * @throws Exception
     */
    public function codeToName(): string
    {
        if (empty($this->code)) {
            throw new Exception('code缺失');
        }
        return $this->codeName($this->code);
    }

    /**
     * 接口状态码
     * @param $code
     * @return string
     */
    protected function codeName($code): string
    {
        $err = [
            '20310' => '姓名为空或非法',
            '20010' => '身份证为空或非法',
            '20004' => '手机号为空或非法',
            '400' => '参数校验不合法',
            '500' => '系统内部错误，请联系服务商',
            '501' => '第三方服务异常',
            '604' => '接口停用',
            '1001' => '其他，以实际返回为准'
        ];
        return $err[$code];
    }
}